import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

const Duration kLimitDuration = Duration(milliseconds: 2000);

class ToastUtils {
  static bool _isShowing = false;

  static Future<bool?> showToast(
    String? msg, {
    Toast length = Toast.LENGTH_SHORT,
    Brightness? brightness,
    ToastGravity? gravity,
    int? code,
  }) {
    if (msg == null || msg.isEmpty || _isShowing) return Future.value(false);
    _isShowing = true;
    Future.delayed(kLimitDuration, () => _isShowing = false);
    return Fluttertoast.showToast(
      msg: msg,
      toastLength: length,
      fontSize: 14,
      gravity: gravity,
      backgroundColor: brightness == Brightness.light
          ? const Color(0xCCFFFFFF)
          : const Color(0x70000000),
      textColor: brightness == Brightness.light ? Colors.black : Colors.white,
    );
  }
}
